package com.bt.controller.user;

import com.bt.context.BaseContext;
import com.bt.entity.YddUser;
import com.bt.result.Result;
import com.bt.service.YddUserService;
import com.bt.vo.UserInfo;
import com.bt.vo.UserInfoVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @Author 张传康
 * @Date 2023-05-04 21:11
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    private YddUserService yddUserService;
    @GetMapping("/getUserInfo")
    public Result<UserInfoVO> UserInfo(){

        Integer currentId = Integer.valueOf(BaseContext.getCurrentId());
        log.info("令牌id是：{}",currentId);
        YddUser yddUser = yddUserService.findById(currentId);
        UserInfo userInfo = UserInfo.builder().birthday(yddUser.getBirthday())
                .password(yddUser.getPassword())
                .notes(yddUser.getNotes())
                .sex(yddUser.getSex())
                .mobile(yddUser.getMobile())
                .icon(yddUser.getIcon())
                .id(yddUser.getId())
                .address(yddUser.getAddress())
                .default_data(yddUser.getDefaultData())
                .username(yddUser.getUsername()).build();

        UserInfoVO userInfoVO = UserInfoVO.builder()
                .userInfo(userInfo)
                .articleNum(0L)
                .zanNum(0L)
                .collectNum(0L).build();
        return Result.success(userInfoVO);
    }
}
